/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Models.DAOs;

/**
 *
 * @author 0905
 */

import DBConnection.ConnectionFactory;
import Models.Log;
import java.lang.Exception;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class Log_DAO {
    
    public boolean addLog(Log log){
        try{
            
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();
            int i = 1;
            PreparedStatement pstmt = conn.prepareStatement("INSERT INTO logs(sessionID, loginTime, userID) VALUES (?,?,?)");
            
            pstmt.setString(i, log.getSessionID());
            pstmt.setString(i, log.getLoginTime());
            pstmt.setInt(i, log.getUserID());
            pstmt.executeUpdate();
            
            return true;
        }
        catch(SQLException e){
            e.printStackTrace();
            return false;
        }
    }
    
    
    public boolean updateLog(Log log){
        
        try{
        
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();
            int i = 1;
            PreparedStatement pstmt = conn.prepareStatement("UPDATE log SET logoutTime = ?");
            pstmt.setString(i++,log.getLogoutTime());
            return true;
        }
        catch(SQLException e){     
            e.printStackTrace();
            return false;
        }
    
    }
    
    
    
    
}
